//
//  HealthDetailViewController.m
//  muscleLife
//
//  Created by xalo on 16/5/4.
//  Copyright © 2016年 HeavenAndHell. All rights reserved.
//

#import "HealthDetailViewController.h"
#import "HealthTableViewCell.h"

@interface HealthDetailViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,retain)NSMutableArray *dataSource;

@end

@implementation HealthDetailViewController

//数据源的懒加载
-(NSMutableArray *)dataSource{
    if (!_dataSource) {
        _dataSource=[NSMutableArray array];
    }
    return _dataSource;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView registerNib:[UINib nibWithNibName:@"HealthTableViewCell" bundle:nil] forCellReuseIdentifier:@"HealthTableViewCell"];
    [self.dataSource addObject:self.model];
    [self.tableView reloadData];
    self.automaticallyAdjustsScrollViewInsets=NO;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

#pragma mark----TableView的代理方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    HealthTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"HealthTableViewCell" forIndexPath:indexPath];
    HealthSearchModel *model=self.dataSource[indexPath.row];
    cell.titleLabel.text=model.title;
    cell.contentLabel.text=model.content;
    cell.contentLabel.adjustsFontSizeToFitWidth=YES;
    return cell;
}
//cell高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    HealthSearchModel *model=self.dataSource[indexPath.row];
    NSString *contentStr=model.content;
    CGRect rect=[contentStr boundingRectWithSize:CGSizeMake(kControllerWidth, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil];
    return CGRectGetHeight(rect)+100;
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
